import http from "@/api/config/http";
import { ITime } from "@/data/options/selection";
import { IQuery, ITableResponse } from "@/interface/IAxios";
import { QueueGroup, QueueItem } from "./types";

// 查询下发队列列表
export function listSendqueue(query?: IQuery): Promise<ITableResponse<QueueItem>> {
  return http.request({
    url: "/sendqueue/sendqueue/list",
    method: "get",
    params: query
  });
}

// 查询下发队列详细
// export function getSendqueue(queueId) {
//   return request({
//     url: '/sendqueue/sendqueue/' + queueId,
//     method: 'get'
//   })
// }

// 删除下发队列
export function delSendqueue(queueId: Array<string>) {
  return http.request({
    url: `/sendqueue/sendqueue/${queueId.join(",")}`,
    method: "delete"
  });
}

// 导出下发队列
export function exportSendqueue(query: ITime) {
  fileTemplate("/sendqueue/sendqueue/export", {
    type: query.time,
    value: query.value
  });
}

// 重新下发数据
export function reissue(queueId: string) {
  return http.request({
    url: `/sendqueue/sendqueue/reissue/${queueId}`,
    method: "get"
  });
}
export function batchReissue(batch: string) {
  return http.request({
    url: `/sendqueue/sendqueue/reissue/batch`,
    method: "get",
    params: {
      batch
    }
  });
}
export function groupsList(query?: IQuery): Promise<ITableResponse<QueueGroup>> {
  return http.request({
    url: `/sendqueue/sendqueue/groupsList`,
    method: "get",
    params: query
  });
}
export function reissueByTime(
  type: "min" | "hour" | "day",
  value: number,
  filterId: string
): Promise<ITableResponse<QueueGroup>> {
  return http.request({
    url: `/sendqueue/sendqueue/reissue`,
    method: "get",
    params: {
      type,
      value,
      filterId
    }
  });
}
